/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.gauss.test;

import fr.vod.gauss.File.File;
import fr.vod.gauss.File.FileImpl;
import fr.vod.gauss.encoder.Encoder;
import fr.vod.gauss.encoder.EncoderImp;
import fr.vod.gauss.matrice.Matrice;
import fr.vod.gauss.matrice.MatriceImpl;
import fr.vod.gauss.matrice.PivotDeGauss;
import fr.vod.gauss.matrice.PivotDeGaussImpl;
import fr.vod.gauss.net.Format;
import fr.vod.gauss.net.FormatImpl;
import fr.vod.gauss.operations.CorpsDeGalloisOperation;

import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 *
 * @author drazanakoto
 */
public class MainFile {

    public static void main(String[] args) throws Exception {
        int BLOCK = 30;
        int PACKET = 10;
        Encoder en = new EncoderImp(new CorpsDeGalloisOperation());
        FileInputStream fis = new FileInputStream("/Users/drazanakoto/Downloads/Extreme - More Than Words.mp3");
        FileOutputStream fos = new FileOutputStream("/Users/drazanakoto/Downloads/more_than_words.mp3");

        File pi = new FileImpl(fis, en, BLOCK, PACKET);
        Matrice m;
        Format f = new FormatImpl();
        PivotDeGauss pdg = new PivotDeGaussImpl(new CorpsDeGalloisOperation());
        boolean resolu = false;

        while (pi.readNextBlock() != -1) {
            m = new MatriceImpl();
            for (int i = 0; i < BLOCK; i++) {
                byte[] tmp = pi.create();
                m.addEquation(f.format(tmp, BLOCK, PACKET));
            }
            resolu = pdg.resoudre(m);
            while (!resolu && m.getLength() < BLOCK) {
                m.addEquation(f.format(pi.create(), BLOCK, PACKET));
                resolu = pdg.resoudre(m);
            }
            fos.write(m.rebuildFile());
        }

        fis.close();
        fos.close();
    }
}
